package xyz.hujf.otherbase.resort;

/**
 * @author Hujf
 * @title: ReadThread
 * @date 2021-04-2315:56
 * @description: TODO
 */
public class Threadt{

    private static int num=0;
    private static volatile boolean isReady = false;

    public static class ReadThread extends Thread{
        @Override
        public void run() {
            while(!Thread.currentThread().isInterrupted()){
                if(isReady){
                    System.out.println(num+num);
                }
                System.out.println("read ok");
            }
        }
    }


    public static class WriteThread extends Thread{

        @Override
        public void run() {
            num=2;
            isReady = true;
            System.out.println("write set is ok");
        }
    }


    public static void main(String[] args) throws InterruptedException {
        ReadThread rt = new ReadThread();
        rt.start();

        WriteThread wt = new WriteThread();
        wt.start();

        Thread.sleep(10);
        rt.interrupt();

    }

}
